<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "order_goods_package".
 *
 * @property int $id
 * @property string $order_no 订单编号
 * @property int $goods_id 商品ID
 * @property string $goods_no 商品编号
 * @property int $first_cate 商品第一分类
 * @property int $package_id 套餐编号
 * @property string $package_name 套餐名称
 * @property string $install_price 安装维护费
 * @property string $price_one 套餐单价
 * @property string $price_total 套餐总价
 * @property int $begin_time 订单开始时间
 * @property int $end_time 订单结束时间
 * @property int $nums 购买数量
 * @property int $addtime 添加时间
 */
class OrderGoodsPackage extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order_goods_package';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_no', 'goods_id', 'goods_no', 'first_cate', 'package_id', 'nums', 'addtime'], 'required'],
            [['order_no', 'goods_id', 'goods_no', 'package_id', 'begin_time', 'end_time', 'nums', 'addtime'], 'integer'],
            [['install_price', 'price_one', 'price_total'], 'number'],
            [['first_cate'], 'string', 'max' => 2],
            [['package_name'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'order_no' => '订单编号',
            'goods_id' => '商品ID',
            'goods_no' => '商品编号',
            'first_cate' => '商品第一分类',
            'package_id' => '套餐编号',
            'package_name' => '套餐名称',
            'install_price' => '安装维护费',
            'price_one' => '套餐单价',
            'price_total' => '套餐总价',
            'begin_time' => '订单开始时间',
            'end_time' => '订单结束时间',
            'nums' => '购买数量',
            'addtime' => '添加时间',
        ];
    }
    
    public static function getPackageByOrderNo($order_no){
        $sql = "select * from order_goods_package where order_no=$order_no";
        $command = \Yii::$app->db->createCommand($sql);
        return $command->queryAll();
    }
    
    public static function getOrderGoodsPackage($order_no,$goods_id){
        $sql = "select * from order_goods_package where order_no=$order_no and goods_id=$goods_id";
        $command = \Yii::$app->db->createCommand($sql);
        return $command->queryAll();
    }
}
